package com.ccs.testdatas;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;


public class AdmissionHCS {

	
	public void admit(WebDriver driver, String option) throws Exception{
		
		//IF OPTION = "hmo" then admission is equals to HMO
		//IF OPTION = "individual" then admission is equals to INDIVIDUAL for LOA
		//IF OPTION = "special" then admission is for OPERATING ROOM
		
		//ADMISSION INFO
		String mainWindow = driver.getWindowHandle();
		driver.switchTo().window(mainWindow);
		Select account = new Select(driver.findElement(By.xpath("//select[@id='accountClass']")));
		driver.findElement(By.xpath("//input[@id='nursingUnitCode']")).clear();
		
		if(option == "hmo"){
			account.selectByVisibleText("HMO");
			Select room = new Select(driver.findElement(By.xpath("//select[@id='roomChargeCode']")));
			room.selectByVisibleText("REGULAR PRIVATE");
			driver.findElement(By.xpath("//input[@id='nursingUnitCode']")).sendKeys("0287");
		}else if(option == "individual"){	
			account.selectByVisibleText("INDIVIDUAL");
			Select room = new Select(driver.findElement(By.xpath("//select[@id='roomChargeCode']")));
			room.selectByVisibleText("REGULAR PRIVATE");
			driver.findElement(By.xpath("//input[@id='nursingUnitCode']")).sendKeys("0287");
		}else if(option == "special"){
			account.selectByVisibleText("HMO");
			driver.findElement(By.xpath("//input[@id='nursingUnitCode']")).sendKeys("0164");
		}
		
		//ROOM AND BED CODE GOES HERE
		driver.findElement(By.xpath("//input[@id='roomNoFinder']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		Actions actions = new Actions(driver);
        WebElement mouseover1 = driver.findElement(By.xpath("//div[@id='roomBedFinderForm']/div[2]/div[1]/input[1]"));
        actions.moveToElement(mouseover1);
        actions.click().perform();
        driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);

        List<WebElement> row = driver.findElements(By.xpath("//tbody[@id='rbf_finder_table_body']/tr"));
		int sizes = row.size();
        System.out.println("No of rooms available: "+sizes);
        driver.findElement(By.xpath("//tbody[@id='rbf_finder_table_body']/tr[1]/td[1]/a")).click();
        driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
        
        if(option=="hmo" || option=="individual"){
        	driver.findElement(By.xpath("//input[@id='diagnosisCode']")).sendKeys("010000");
			driver.findElement(By.xpath("//input[@id='guarantorTelNo']")).sendKeys("12345");
        }
		
		driver.findElement(By.xpath("//input[@id='doctorCode']")).sendKeys("5825");
		
		//GUARANTOR
		if(option=="special"){
			driver.findElement(By.xpath("//input[@id='guarantorCode']")).sendKeys("COHC001");
			Select room = new Select(driver.findElement(By.xpath("//select[@id='guarantorRelationCode']")));
			room.selectByVisibleText("GUARANTOR");
		}else if(option=="individual"){
			driver.findElement(By.xpath("//input[@id='searchClaimedGuarantorBtn']")).click();
			driver.findElement(By.xpath("//input[@id='hmoCom_entity_finder_key']")).sendKeys("Cocolife");
			driver.findElement(By.xpath("//div[@id='hmoComFinderForm']/div[2]/div[1]/input[2]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		}else if(option=="hmo"){
			driver.findElement(By.xpath("//input[@id='searchGuarantorBtn']")).click();
			driver.findElement(By.xpath("//input[@id='bp_entity_finder_key']")).sendKeys("COHC001");
			driver.findElement(By.xpath("//div[@id='bpFinderForm']/div[2]/div[1]/input[2]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			Select room = new Select(driver.findElement(By.xpath("//select[@id='guarantorRelationCode']")));
			room.selectByVisibleText("GUARANTOR");
		}
		
		//button preview admission
		if(option=="hmo" || option=="individual"){
			driver.findElement(By.xpath("//input[@id='guarantorTelNo']")).sendKeys("12345");
			driver.findElement(By.xpath("//input[@value='Preview']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
		}else if(option=="special"){
			driver.findElement(By.xpath("//input[@id='previewAction']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
		}
		
	}
	
	public void save_admission(WebDriver driver, String option){
		
		if(option=="hmo" || option=="individual"){
			
			//save admission
			driver.findElement(By.xpath("//input[@value='Save Admission']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
		}else if(option=="special"){
			
			//save admission
			driver.findElement(By.xpath("//input[@value='Save']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
		}
		
		
	}
	
}
